<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-inline">
                <label class="layui-form-label w-auto">负责人：</label>
                <div id="responsibilityPerson"></div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">投放平台：</label>
                <div id="pMedia" style="width:100%;flex:1"></div>
            </div>
            <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
            <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            <button type="button" id="leading-out" class="layui-btn layui-btn-normal">导出</button>
        </form>
    </div>
    <table id="launchDetail" lay-filter="launchDetail"></table>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    </script>
    <script>
        let id = GetQueryString('id')
        let totalObj = {}
        let params = {
            id
        }
        layui.use(['table', "form", "layer"], function () {
            var table = layui.table
            form = layui.form,
                layer = layui.layer;

            let tableOptions = {
                elem: '#launchDetail'
                , url: `/cps/launch/peopleDetail?id=${id}` //数据接口
                , id: 'launchDetail'
                , where: params
                , page: true
                , limit: 15
                , totalRow: true
                , cols: [[ //表头
                    { field: 'month', width: 90, title: '月份', align: 'center', totalRowText: '总合计：' }
                    , { field: 'responsibility_person_name', width: 110, title: '负责人', align: 'center' }
                    , { field: 'cost', title: '消耗', align: 'center',}
                    , { field: 'actual_cost', title: '实际消耗', align: 'center',}
                    , { field: 'register_user_num', title: '注册用户',width:100, align: 'center',}
                    , { field: 'activation_user_num', title: '激活用户',width:100, align: 'center',}
                    , { field: 'current_recharge', title: '充值', align: 'center',}
                    , { field: 'total_recharge', title: '累计充值', align: 'center',}
                    , { field: 'current_income', title: '收益', align: 'center',}
                    , { field: 'total_income', title: '累计收益', align: 'center',}
                    , { field: 'current_recovery', title: '返后ROI',width:100, align: 'center' }
                    
                    
                    , { field: 'total_recovery', title: '累计ROI', align: 'center' }
                    , { field: 'revenue', title: '利润', align: 'center',}
                    , { field: 'recharge_number', title: '订单数', width:80, align: 'center',}
                    , { field: 'conversion_number', title: '充值人数', width:90, align: 'center',}
                    
                    , { field: 'per_capita_contribution', width: 115, title: '人均充值', align: 'center',}
                    , { toolbar: '#tbBar', title: '操作', align: 'center', width: 80 }
                ]],
                customTotal:function(wheres){
                    getTotal('/cps/launch/peopleDetailCount',totalObj,wheres).then(val=>{
                        totalObj = val
                    })
                },
                done: function (res, curr, count) {
                    setPrice(totalObj)
                },
                reset: function(){
                    tableOptions.where = params;
                    
                    selectParams1.selected = [id]
                    selectN(selectParams1)
                }
            };
            tableList(tableOptions)
            form.on('submit(searchList)', function (data) {
                params = data.field;
                if(params.id == ''){
                    layer.msg('请选择负责人',{icon:5,time:2000}); 
                    return false;
                }
                return false
            });
            table.on('tool(launchDetail)', function (obj) {
                var event = obj.event;
                if (event === 'look') {
                    let { responsibility_person_id, month } = obj.data;
                    x_admin_show('查看', `./peopleIndex.html?responsibility_person_id=${responsibility_person_id}&month=${month}`, 1400, 600, null);
                }
            });
        })


        $("#leading-out").click(function() {
            var data = $('form').serialize();
            derive('/cps/export/byMonthViewExport',data)
        });

        let selectParams1 = {
            url: '/cps/responsibilityPerson/select?type=1',
            elem: '#responsibilityPerson',
            selected: [id],
            tips: '选择负责人',
            name: 'id',
            field_id: 'responsibility_person_id',
            field_Name: 'responsibility_person_name',
        }
        selectN(selectParams1)
        let selectMedia = {
            url: '/cps/launch/getLaunchMedia',
            selected: [],
            tips: '选择平台',
            name: 'media_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMedia'
        }
        selectN(selectMedia)
        
        function setPrice(totalObj){
            Object.keys(totalObj).forEach(item=>{
                $(`.layui-table-total td[data-field=${item}] .layui-table-cell`).text(totalObj[item]);
            })
        }
    </script>
</body>

</html>